package com.bins.performance.testing.log;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
public class LogController {

    private static final Integer count = 1000;

    @GetMapping("/testDebug")
    public String testDebug() {
        for (int i = 0; i < count; i++) {
            log.debug(new B() + "3" + "4");
        }
        return "success";
    }


    @GetMapping("/testDebugForEnabled")
    public String testDebugForEnabled() {
        for (int i = 0; i < count; i++) {
            if (log.isDebugEnabled()) {
                log.debug(new B() + "3" + "4");
            }
        }
        return "success";
    }

    @GetMapping("/testDebugForEnabled2")
    public String testDebugForEnabled2() {
        for (int i = 0; i < count; i++) {
            log.debug("日志：{}, {}", "3", "4");
        }
        return "success";
    }

    public class B {
        private byte[] b = new byte[1024 * 1024];

        public B() {
            System.out.println("B的初始化");
        }
    }
}
